package yangan.faultHandler;

import app.nbdevices.service.IFaultService;
import com.mess.warningmess.Bean4WarnMessInfo;
import com.mess.warningmess.WarningMass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import yangan.entity.YanganDataReport;
import yangan.mapper.YanganDataReportMapper;
import yangan.modle.codecModel.YanganCycleReport;
import yangan.modle.codecModel.YanganEventReport;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.List;

@Component
public class YanganFaultHandler {

    @Autowired
    IFaultService svcFault;

    @Autowired
    YanganDataReportMapper yanganDataReportMapper;

    public void cycleHandler(YanganDataReport yanganDataReport){
        ArrayList<Integer> faultTypeIds=new ArrayList<>();
        if(yanganDataReport.getYanganVoltage()<3.2){
            //烟感电池欠电
            svcFault.saveEventLog(yanganDataReport.getInternetDeviceId(),7,11);
            faultTypeIds.add(11);
        }
        svcFault.updateEventLog(yanganDataReport.getInternetDeviceId(),faultTypeIds,"1");
    }

    public void eventHandler(YanganDataReport yanganDataReport){
        switch(yanganDataReport.getCId()){
            case 1110: fireHandler(yanganDataReport.getInternetDeviceId());
                break;
        }
    }

    public void dropLine(){
        Long second = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
        List<YanganDataReport> res=yanganDataReportMapper.selectNewData();
        for(YanganDataReport y:res){
            if(second-y.getReportTime()>60*60*26){
                svcFault.saveEventLog(y.getInternetDeviceId(),7,12);
            }
        }
    }

    private void fireHandler(String internetDeviceId){
        svcFault.saveEventLog(internetDeviceId,18,16);
    }
}
